import torch

if torch.cuda.is_available():
    device = torch.device("cuda")
    x = torch.randn(2, 3, device=device)
    print(x.device)  # 应输出: cuda:0
else:
    print("CUDA 不可用")